<?php
/**
 * @copyright Copyright (c) 2021 勾股工作室
 * @license https://opensource.org/licenses/GPL-3.0
 * @link https://www.gougucms.com
 */

namespace app\cert\model;

use think\facade\Db;
use think\Model;

class CertSales extends Model
{
    public static $Status = [
        0 => '待上报',
        1 => '已上报',
        2 => '已初审',
        3 => '已复审',
        4 => '已通过',
        5 => '',
        8 => '已驳回',
    ];
	
	//列表检索
    public function get_list($param = [], $where = [], $whereOr=[])
    {

        $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
        $list = self::where($where)
            ->where(function ($query) use($whereOr) {
					$query->whereOr($whereOr);
			})
			->field('a.*')
			->alias('a')
            ->order('a.status asc,a.create_time desc')
			->paginate($rows, false, ['query' => $param])
			->each(function ($item, $key) {
                $item->status_name = self::$Status[(int)$item->status];
			});
        return $list;
    }
	
	
    // 获取合同详情
    public function detail($id)
    {
        $detail = self::where(['id' => $id])->find();
        if (!empty($detail)) {				
			$share_names = Db::name('Admin')->where([['id','in',$detail['share_ids']]])->column('name');
			$detail['share_names'] = implode(',',$share_names);
			if($detail['file_ids'] !=''){
				$fileArray = Db::name('File')->where('id','in',$detail['file_ids'])->select();
				$detail['fileArray'] = $fileArray;
//                $detail['license_cert'] =  Db::name('license_cert')->where('license_id', $detail['id'])->where('is_delete', 0)->select();
            }
        }
        return $detail;
    }
}
